package com.wzh.yebServe.excepton;

import com.wzh.yebServe.pojo.ResultBean;
import org.springframework.web.bind.annotation.ExceptionHandler;

import java.sql.SQLException;
import java.sql.SQLIntegrityConstraintViolationException;

/**
 * @Author wzh
 * @create 2022/11/14 22:04
 * @Description:全局异常处理
 */
public class GlobalException {
    @ExceptionHandler(SQLException.class)
    public ResultBean mysqlException(SQLException e){
        if (e instanceof SQLIntegrityConstraintViolationException){
            return ResultBean.error("修改改数据有关联数据，操作失败");
        }
        return ResultBean.error("数据库异常");
    }
}
